/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.Driver;

import br.ufg.inf.si.poo.formula1.Team.Team;

/**
 * Driver
 * 
 * Versao 1.0
 * 
 * Data 20/01/2013
 * 
 * @author Igor
 */
public class Driver {
    //Atributos
    private String driverName;
    private Team team;
    private String nationality;
    private int podiums;
    private int points;
    private int grandPrixEntered;
    private int worldChampionships;
    private int[] highestRaceFinish;
    private int[] highestGridPosition;
    private String dateBirth;
    private String placeBirth;

    //Construtores
    public Driver(){
        this.driverName = "";
        this.team = null;
        this.nationality = "";
        this.podiums = 0;
        this.points = 0;
        this.grandPrixEntered = 0;
        this.worldChampionships = 0;
        this.highestRaceFinish = new int[2];
        this.highestRaceFinish[0] = 0;
        this.highestRaceFinish[1] = 0;
        this.highestGridPosition = new int[2];
        this.highestGridPosition[0] = 0;
        this.highestGridPosition[1] = 0;
        this.dateBirth = "";
        this.placeBirth = "";
    }

    public Driver(
            String driverName,
            String nationality,
            int podiums,
            int grandPrixEntered,
            int worldChampionships,
            int[] highestRaceFinish,
            int[] highestRacePosition,
            String dateBirth,
            String placeBirth
            ){
        /* Esse construtor recebe estes parametros pois o sao os dados que 
         o arquivo INICIAl contem */
        this.driverName = driverName;
        this.team = null;
        this.nationality = nationality;
        this.podiums = podiums;
        this.points = 0;
        this.grandPrixEntered = grandPrixEntered;
        this.worldChampionships = worldChampionships;
        this.highestRaceFinish = new int[2];
        this.highestRaceFinish[0] = highestRaceFinish[0];
        this.highestRaceFinish[1] = highestRaceFinish[1];
        this.highestGridPosition = new int[2];
        this.highestGridPosition[0] = highestRacePosition[0];
        this.highestGridPosition[1] = highestRacePosition[1];
        this.dateBirth = dateBirth;
        this.placeBirth = placeBirth;
    }

    //Metodos Getters and Setters
    /**
     * Retorna o atributo driverName (nome do piloto)
     * @return atributo driverName
     */
    public String getDriverName() {
        return this.driverName;
    }

    /**
     * Altera o atributo driverName (nome do piloto)
     * @param atributo driverName
     */
    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    /**
     * Retorna o atributo team (equipe do piloto)
     * @return a equipe "team" 
     */
    public Team getTeam() {
        return team;
    }

    /**
     * Altera o atributo team (equipe do piloto)
     * @param a equipe "team" 
     */
    public void setTeam(Team team) {
        this.team = team;
    }

    /**
     * Retorna o atributo nationality (nacionalidade do piloto)
     * @return a nacionalidade "nationality" 
     */
    public String getNationality() {
        return nationality;
    }

    /**
     * Altera o atributo nationality (nacionalidade do piloto)
     * @param a nacionalidade "nationality"
     */
    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    /**
     * Retorna o atributo podiums (quantos podiums o piloto participou)
     * @return o atributo podiums
     */
    public int getPodiums() {
        return podiums;
    }

    /**
     * Altera o atributo podiums (quantos podiums o piloto participou)
     * @param atributo podiums
     */
    public void setPodiums(int podiums) {
        this.podiums = podiums;
    }

    /**
     * Retorna o atributo  points (pontos do piloto
     * @return atributo points
     */
    public int getPoints() {
        return points;
    }

    /**
     * Altera o atributo points (pontos do piloto)
     * @param atributo points
     */
    public void setPoints(int points) {
        this.points = points;
    }

    /**
     * Retorna o atributo grandPrixEntered (quantos grande prix entrou)
     * @return atributo grandPrixEntered
     */
    public int getGrandPrixEntered() {
        return grandPrixEntered;
    }

    /**
     * Altera o atributo grandPrixEntered (quantos grande prix entrou)
     * @param atributo grandPrixEntered
     */
    public void setGrandPrixEntered(int grandPrixEntered) {
        this.grandPrixEntered = grandPrixEntered;
    }

    /**
     * Retorna o atributo worldChampionships (quantas vezes foi campeao mundial)
     * @return atributo worldChampionships
     */
    public int getWorldChampionships() {
        return worldChampionships;
    }

    /**
     * Altera o atributo worldChampionships (quantas vezes foi campeao mundial)
     * @param atributo worldChampionships
     */
    public void setWorldChampionships(int worldChampionships) {
        this.worldChampionships = worldChampionships;
    }

    /**
     * Retorna o atributo highestRaceFinish (melhor posicao em corrida)
     * @return atributo highestRaceFinish
     */
    public int[] getHighestRaceFinish() {
        return highestRaceFinish;
    }

    /**
     * Altera o atributo highestRaceFinish (melhor posicao em corrida)
     * @param vetor highestRaceFinish
     */
    public void setHighestRaceFinish(int highestRaceFinish) {
        if( (highestRaceFinish < this.highestRaceFinish[0]) || (this.highestRaceFinish[0] == 0) ){
            this.highestRaceFinish[0] = highestRaceFinish;
            this.highestRaceFinish[1] = 1;
        }else if(highestRaceFinish ==  this.highestRaceFinish[0]){
            this.highestRaceFinish[1]++;
        }
    }

    /**
     * Retorna o atributo highestGridPosition (melhor posicao em corrida)
     * @return vetor highestGridPosition
     */
    public int[] getHighestGridPosition() {
        return highestGridPosition;
    }

    /**
     * Altera o atributo highestGridPosition (melhor posicao em corrida)
     * @param vetor highestGridPosition
     */
    public void setHighestGridPosition(int highestGridPosition) {
        if( (highestGridPosition < this.highestGridPosition[0]) || (this.highestGridPosition[0] == 0) ){
            this.highestGridPosition[0] = highestGridPosition;
            this.highestGridPosition[1] = 1;
        }else if(highestGridPosition ==  this.highestGridPosition[0]){
            this.highestGridPosition[1]++;
        }
    }

    /**
     * Retorna o atributo dateBirth (data de nascimento)
     * @return atributo dateBirth
     */
    public String getDateBirth() {
        return dateBirth;
    }

    /**
     * Altera o atributo dateBirth (data de nascimento)
     * @param atributo dateBirth
     */
    public void setDateBirth(String dateBirth) {
        this.dateBirth = dateBirth;
    }

    /**
     * Retorna o atributo placeBirth (local de nascimento)
     * @return atributo placeBirth
     */
    public String getPlaceBirth() {
        return placeBirth;
    }

    /**
     * Altera o atributo placeBirth (local de nascimento)
     * @param placeBirth
     */
    public void setPlaceBirth(String placeBirth) {
        this.placeBirth = placeBirth;
    }

    //Outros Metodos
    /**
     * Reescrita do metodo toString
     * Retorna uma String com o relatório de dados do Piloto
     * @return String com o relatório de dados de Pilotos
     */
    @Override
    public String toString(){
        String data = "";

        data += this.driverName + "\n"
                + "________________________________________________\n"
                + "Team:\t\t\t"; 
        if(this.team != null){
            data += this.team.getShortName();
        }
        data += "\n"
                + "Nationality:\t\t" + this.nationality + "\n"
                + "Podiums:\t\t" + this.podiums + "\n"
                + "Points:\t\t\t" + this.points + "\n"
                + "Grand Prix entered:\t" + this.grandPrixEntered + "\n"
                + "World Championships:\t" + this.worldChampionships + "\n"
                + "Highest race finish:\t" + this.highestRaceFinish[0] + " (x" + this.highestRaceFinish[1] + ")" + "\n"
                + "Highest grid position:\t" + this.highestGridPosition[0] + " (x" + this.highestGridPosition[1] + ")" + "\n"
                + "Data of Birth:\t\t" + this.dateBirth + "\n"
                + "Place of Birth:\t\t" + this.placeBirth + "\n";

        return data;
    }
    
    /**
     * Reescrita do metodo equals
     * Verifica se o piloto passado como paramentro e o mesmo piloto do objeto são iguais
     * @param anObject
     * @return 
     */
    @Override
    public boolean equals(Object anObject) {
        if(anObject instanceof Driver){
            if(this.driverName.equals(((Driver) anObject).getDriverName())){
                return true;
            }
        }
        return false;
    }

    /**
     * Reescrita do hashCode, devido a reescrita do metodo equals
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.driverName != null ? this.driverName.hashCode() : 0);
        return hash;
    }
}
